<?php
/*
    ID:   $Id: $
    Name: John Griffin
    Date: May 26,2009
*/
$dir = preg_replace ('/\/trunk\/.*/', '/trunk', __FILE__);
ini_set ('include_path', $dir.'/source:'.$dir.'/test:'.ini_get ('include_path'));

require_once 'simpletest/autorun.php';
require_once 'lib/Validator.php';

class TestValidator extends UnitTestCase {
    private $cwd = '';
    private $resource = null;
    
    public function __construct () {
        parent::__construct ();
        $this->cwd = dirname (__FILE__);
        $this->resource = simplexml_load_file ($this->cwd.'/test_Validator/simpleXMLObject.xml');
    }
    
    private function fileGetContents ($filename, $contents) {
        $path = $this->cwd.'/'.$filename;
        if (file_exists ($path) == true) {
            $return = file_get_contents ($path);
        } else {
            file_put_contents ($path, $contents);
            chmod ($path, 0666);
            $return = $contents;
        }
        return $return;
    }

    public function testInvoke () {
        $error = new Error ();
        $validator = new Validator ($this->resource, $error);
        $this->assertTrue (true);
    }
    
    public function testValidateIds1 () {
        $error = new Error ();
        $validator = new Validator ($this->resource, $error);
        $validator->validateIds (array (1));
        $this->assertTrue (count ($error) == 0);
    }

    public function testValidateIds2 () {
        $error = new Error ();
        $validator = new Validator ($this->resource, $error);
        $validator->validateIds (array (-1));
        $this->assertTrue (count ($error) == 0);
    }

    public function testValidateIds3 () {
        $error = new Error ();
        $validator = new Validator ($this->resource, $error);
        $validator->validateIds (array ('a'));
        $this->assertTrue (count ($error) == 1);
    }
}
?>
